<template>
	<div class="invite">
		<div class="space"></div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				<span>*</span> 性别
			</div>
			<div class="inviteIndexItems_right" @click="showSex = true; hideKeyboard()">
				<!-- <input type="text" value="" placeholder="请输入性别" /> -->
				<u--input v-model="from.userInfo.sex" disabled disabledColor="#ffffff" placeholder="请选择性别"
					border="none"></u--input>
				<u-icon slot="right" name="arrow-right" color='#c0c4cc'></u-icon>
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				<span>*</span> 姓名
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" v-model='from.userInfo.name' placeholder="请输入姓名" />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				<span>*</span> 身份证号
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" v-model='from.userInfo.idcard' maxlength="18" placeholder="请输入身份证号" />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				<span>*</span> 联系方式
			</div>
			<div class="inviteIndexItems_right">
				<input type="number" value="" disabled v-model='from.userInfo.phone' maxlength="11"
					placeholder="请输入联系方式" />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				<span>*</span> 直播花名
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.nickname' />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				<span>*</span> 抖音号(大号)
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.big_doyin' />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				抖音号(小号)
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.small_doyin' />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				抖音号(小号)
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.smalls_doyin' />
			</div>
		</div>

		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				抖音号(小号)
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.smallss_doyin' />
			</div>
		</div>
		<!-- 		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				抖音号(小号)
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.smallsss_doyin' />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				抖音号(小号)
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.smallssss_doyin' />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				抖音号(小号)
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.smallsssss_doyin' />
			</div>
		</div> -->
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				<span>*</span> 运营
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" disabled v-model='from.userInfo.operate' />
			</div>
		</div>

		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				<span>*</span> 是否养宠
			</div>
			<div class="inviteIndexItems_right">
				<!-- <input type="text" value="" placeholder="请输入" v-model='from.userInfo.pet' /> -->
				<u-radio-group v-model="from.userInfo.pet" placement="row" @chage='changeRadio'>
					<u-radio label="是" name='是' style="margin-right: 40rpx;"></u-radio>
					<div style="width: 40rpx;"></div>
					<u-radio label="否" name='否'></u-radio>
				</u-radio-group>

			</div>
		</div>
		<!-- title -->
		<div class="inviteIndexItems_title">
			同住/随行人员(仅限直系亲属同住)
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				姓名
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.names' />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				性别
			</div>
			<div class="inviteIndexItems_right" @click="showSexs = true; hideKeyboard()">
				<!-- <input type="text" value="" placeholder="请输入" /> -->
				<u--input v-model="from.userInfo.sexs" disabled disabledColor="#ffffff" placeholder="请选择性别"
					border="none"></u--input>
				<u-icon slot="right" name="arrow-right" color='#c0c4cc'></u-icon>
			</div>
		</div>
		<!-- <div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				直播花名
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.nicknames' />
			</div>
		</div> -->
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				身份证号码
			</div>
			<div class="inviteIndexItems_right">
				<input type="number" value="" placeholder="请输入" maxlength="18" v-model='from.userInfo.idcards' />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				与入住人关系
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.relations' />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				联系方式
			</div>
			<div class="inviteIndexItems_right">
				<input type="number" value="" placeholder="请输入" maxlength="11" v-model='from.userInfo.phones' />
			</div>
		</div>
		<!-- title -->
		<div class="inviteIndexItems_title">
			紧急联系人
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				<span>*</span> 姓名
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.worry_name' />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				<span>*</span> 与入住人关系
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" v-model='from.userInfo.worry_relation' />
			</div>
		</div>
		<div class="inviteIndexItems">
			<div class="inviteIndexItems_left">
				<span>*</span> 联系方式
			</div>
			<div class="inviteIndexItems_right">
				<input type="text" value="" placeholder="请输入" maxlength="11" v-model='from.userInfo.worry_phone' />
			</div>
		</div>

		<!-- 身份证上传 -->
		<div class="inviteUpdate">
			<span>*</span> 身份证上传
		</div>
		<div class="inviteUpdate_img">
			<div class="inviteUpdate_left" @click='UpImg(1)'>
				<image :src="from.userInfo.front" mode="" v-if="from.userInfo.front"></image>
				<image src="https://wx.sjcmhz.com/static/image/index16.png" mode="" v-else></image>
			</div>
			<div class="inviteUpdate_right" @click='UpImg(2)'>
				<image :src="from.userInfo.back" mode="" v-if="from.userInfo.back"></image>
				<image src="https://wx.sjcmhz.com/static/image/index16.png" mode="" v-else></image>
			</div>
		</div>
		<div class="space"></div>
		<!-- 底部按钮 -->
		<div class="inviteIndexItems_bottom">
			<!-- 富文本 -->
			<div class="inviteIndexItems_fwb" @click='richEvent()'>
				提交申请即代表同意<span>《苏江传媒线下主播日常规范》</span>

			</div>
			<!-- 提交 -->
			<div :class="isRead===1?'inviteIndexItems_btn':'inviteIndexItems_btn color_hui' "
				@click='inviteSureEvent()'>
				提交申请
			</div>
		</div>


		<u-action-sheet :show="showSex || showSexs" :actions="actions" title="请选择性别" @close="showSex = false"
			@select="sexSelect">
		</u-action-sheet>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				from: {
					userInfo: {
						anchor_id: uni.getStorageSync('author_id') || 1,
						sex: '',
						name: '',
						idcard: '',
						front: '',
						back: '',
						phone: '',
						big_doyin: '',
						// small_doyin: '',
						// smalls_doyin: '',
						// operate: '',
						nickname: '',
						pet: '是',
						// sexs: '',
						// names: '',
						// nicknames: '',
						// idcards: '',
						// relations: '',
						// phones: '',
						worry_name: '',
						worry_relation: '',
						worry_phone: '',
					}
				},
				actions: [{
						name: '男',
					},
					{
						name: '女',
					},

				],
				showSex: false,
				showSexs: false,
				status: '',
				isRead: 2, //是否阅读
			}
		},
		onShow() {
			this.isRead = uni.getStorageSync('isRead')
			setTimeout((res) => {
				uni.setStorageSync('isRead', 2)
			}, 2000)
		},
		onLoad(opt) {
			this.status = opt.status
			this.getUserInfo()
		},
		mounted() {
			// console.log(1111,uni.$u.config.v);	
		},
		methods: {
			changeRadio(e) {
				console.log("222", e, this.from.userInfo.pet)
			},
			richEvent() {
				uni.navigateTo({
					url: '/pagesA/index/rich_text/rich_text'
				})
			},
			async getUserInfo() {
				const {
					data
				} = await this.$request(this.$Api.indexDetail, {
					anchor_id: this.from.userInfo.anchor_id
				}, "POST")
				if (data.code !== 0) return
				this.from.userInfo = data.data
			},
			// 上传图片
			UpImg(index) {
				var that = this
				uni.chooseImage({
					count: 1,
					sourceType: ['album'],
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						that.thumbnail = tempFilePaths
						that.UpList(index, that.thumbnail)
					}
				});
			},
			UpList(index, file) {
				var that = this
				that.$utils.UpdataImg(file, (res) => {
					console.log("resssssss", res)
					if (index == 1) {
						that.$set(that.from.userInfo, 'front', res[0])
					} else if (index == 2) {
						that.$set(that.from.userInfo, 'back', res[0])
					}

				})
			},
			sexSelect(e) {
				this.from.userInfo.sex = e.name
				if (this.showSex) {
					this.$set(this.from.userInfo, 'sex', e.name)
				} else if (this.showSexs) {
					this.$set(this.from.userInfo, 'sexs', e.name)
				}
				this.showSexs = this.showSex = false
				console.log("e.name", e.name, this.from.userInfo)
			},
			hideKeyboard() {

			},
			async inviteSureEvent() {
				if (this.isRead !== 1) return uni.showToast({
					title: '请阅读苏江传媒线下主播日常规范',
					icon: 'none'
				})
				console.log(this.from.userInfo)
				this.from.userInfo.addresstime = '1'
				this.from.userInfo.addtime = '1'
				this.from.userInfo.remark = '1'
				this.from.userInfo.type = '1'

				if (/^[1-9]\d{5}(18|19|20|21|22)?\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}(\d|[Xx])$/.test(this
						.from.userInfo.idcard)) {} else {
					return uni.showToast({
						title: '请输入正确的身份证号',
						icon: 'none'
					})
				}
				if (this.from.userInfo.idcards) {
					if (/^[1-9]\d{5}(18|19|20|21|22)?\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}(\d|[Xx])$/.test(
							this
							.from.userInfo.idcards)) {} else {
						return uni.showToast({
							title: '请输入正确的随同人身份证号',
							icon: 'none'
						})
					}
				}
				if(this.from.userInfo.phones){
					if (/^1[3-9]\d{9}$/.test(this.from.userInfo.phones)) {
					
					} else {
						return uni.showToast({
							title: '请输入正确的随同人联系方式',
							icon: 'none'
						})
					}
				}

				if (/^1[3-9]\d{9}$/.test(this.from.userInfo.worry_phone)) {

				} else {
					return uni.showToast({
						title: '请输入正确的紧急联系人联系方式',
						icon: 'none'
					})
				}
				const yzinfo = {
					sex: this.from.userInfo.sex,
					name: this.from.userInfo.name,
					idcard: this.from.userInfo.idcard,
					front: this.from.userInfo.front,
					back: this.from.userInfo.back,
					phone: this.from.userInfo.phone,
					big_doyin: this.from.userInfo.big_doyin,
					nickname: this.from.userInfo.nickname,
					pet: '是',
					worry_name: this.from.userInfo.worry_name,
					worry_relation: this.from.userInfo.worry_relation,
					worry_phone: this.from.userInfo.worry_phone,
				}

				const s = this.$utils.isObjectEmpty(yzinfo)
				console.log('11111', s)
				if (s !== true) return uni.showToast({
					title: '请补全信息',
					icon: 'none'
				})
				const {
					data
				} = await this.$request(this.$Api.indexAuth, this.from.userInfo, "POST")
				if (data.code !== 0) return uni.showToast({
					title: '系统错误',
					icon: 'none'
				})
				uni.navigateTo({
					url: '/pages/invite/inviteSure'
				})
			}
		}
	}
</script>

<style lang="less">
	.space {
		width: 100%;
		height: 22rpx;
	}

	.inviteIndexItems {
		display: flex;
		align-items: center;
		justify-content: flex-start;
		width: 750rpx;
		height: 100rpx;
		border-bottom: 1rpx solid #eee;
		background: #fff;
		padding: 0 44rpx;
		box-sizing: border-box;

		.inviteIndexItems_left {
			color: #494949;
			font-size: 30rpx;
			width: 240rpx;

			span {
				color: red;
				margin-right: 8rpx;
			}
		}

		.inviteIndexItems_right {
			color: #999999;
			font-size: 28rpx;
			display: flex;
			justify-content: space-between;
			width: calc(100% - 240rpx);
		}
	}

	.inviteUpdate {
		font-size: 30rpx;
		line-height: 94rpx;
		padding: 0 44rpx;

		span {
			color: red;
			margin-right: 8rpx;
		}


	}

	.inviteUpdate_img {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		padding: 0 22rpx;
		box-sizing: border-box;
		margin-bottom: 10rpx;
	}

	.inviteUpdate_left,
	.inviteUpdate_right {
		width: 344rpx;
		height: 188rpx;

		// float:left;
		image {
			width: 100%;
			height: 100%;

		}
	}

	.inviteIndexItems_title {
		height: 100rpx;
		line-height: 100rpx;
		padding: 0 44rpx;
		font-size: 30rpx;

	}

	.inviteIndexItems_bottom {
		// position: fixed;
		// bottom: 0;
		// left: 0;
		margin-top: 50rpx;

		.inviteIndexItems_fwb {
			width: 750rpx;
			height: 88rpx;
			background: #FFFFFF;
			font-size: 28rpx;
			line-height: 88rpx;
			padding: 0 44rpx;

			span {
				color: #9013FE;
			}
		}

		.inviteIndexItems_btn {
			width: 750rpx;
			height: 100rpx;
			background: #9013FE;
			line-height: 100rpx;
			font-size: 28rpx;
			text-align: center;
			color: #fff;
		}

	}

	.color_hui {
		background: #666 !important;
	}
</style>